package com.erification.web.service.impl;

import javax.crypto.Cipher;

import org.springframework.stereotype.Service;

import com.erification.web.dataTransfer.KeyManager;
import com.erification.web.service.TransferService;
@Service("transferService")
public class TransferServiceImpl implements TransferService {
	
	@Override
	public byte[] encrypt(String massage, KeyManager keyManager) {
		Cipher cipher = null;
		byte[] result = null;
		try {
			cipher = cipher.getInstance("DES");
			cipher.init(Cipher.ENCRYPT_MODE, keyManager.getSenderDesKey());
			result = cipher.doFinal(massage.getBytes());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public String decrypt(byte[] message, KeyManager keyManager) {
		Cipher cipher = null;
		String result = null;
		try {
			cipher = Cipher.getInstance("DES");
			cipher.init(Cipher.DECRYPT_MODE, keyManager.getReceiverDesKey());
			result = new String(cipher.doFinal(message));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

}
